var task = {
    config: {},
    init: function (d) {
        $.extend(this.config, d, true);
        //this.getvtBind();
        this.imageshow();
        //  this.submitTask();
    },
    /*
     * 点击开始任务
     */
    getvtBind: function () {
        var $taskClick = $(".weui_media_title a.getvt"),
                _self = this;
        $taskClick.bind("click", function () {
            var that = $(this),
                    $taskid = that.attr("data-taskid");
            that.attr("disabled", true);
            $.post(_self.config.taskUrl, {"taskid": $taskid}, function (data) {
                if (data.status === true) {
                    location.href = data.url;
                } else {
                    $.alert(data.msg);
                    that.removeAttr("disabled");
                }
            }, "json");
        });
    },
    /*
     * 隐藏任务
     */
    hideBtn: function () {
        var _self = this,
                $hideBtn = $(_self.config.hideBtn);
        $hideBtn.click(function () {
            var that = $(this),
                    $id = that.attr("id"),
                    $action = that.attr("action"),
                    $tip = that.attr("tip");
            $.confirm($tip, function () {
                $.ajax({
                    url: _self.config.hideUrl,
                    type: "post",
                    data: {"id": $id, "action": $action},
                    beforeSend: function (e) {
                    },
                    success: function (data) {
                        if (data.status === true) { //成功
                            $.alert("操作成功");
                            setTimeout(function () {
                                location.href = data.url;
                            }, 1000);
                        } else { //失败
                            $.alert(data.msg);
                        }
                    }, dataType: "json"});
            });
        });
    },
    /*
     * 上传图片绑定
     */
    upImgbind: function () {
        $("#qrpickfiles").change(function (e) {
            var that = $(this);
            $(".weui_uploader_files").empty().append('<li class="weui_uploader_file" style="background-image:url(\'' + window.URL.createObjectURL(that[0].files[0]) + '\')"><span class="gr-remove" style="color:red;margin:-5px 4px;float:right;cursor:pointer;">X</span></li>');
            $(".weui_uploader_files li span").unbind().bind("click", function () {
                $(this).parent().remove();
            });
        });
        $("#qrpickfiles2").change(function (e) {
            var that = $(this);
            $(".weui_uploader_files2").empty().append('<li class="weui_uploader_file" style="background-image:url(\'' + window.URL.createObjectURL(that[0].files[0]) + '\')"><span class="gr-remove" style="color:red;margin:-5px 4px;float:right;cursor:pointer;">X</span></li>');
            $(".weui_uploader_files2 li span").unbind().bind("click", function () {
                $(this).parent().remove();
            });
        });
    },
    /*
     * 提交任务
     */
    submitTask: function () {
        $("#btnSubmit").click(function () {
            $(this).attr("disabled","disabled");
            if (confirm("注意：即日起狠抓错误、假图、不成功图、发现一次，永久封号。确认提交此任务？")) {
                var $len = $(".weui_uploader_files li").length;
                var $len2 = $(".weui_uploader_files2 li").length;
                var count = $("#addForm").attr("imglen");
                if (($len+$len2) != count) {
                    $.alert("亲，任务需求:请上传" + count + "张图，您上传了" + $len + "张提交失败，请重试");
                    $(this).removeAttr("disabled");
                    return false;
                }
                $("#addForm").submit();
            }else{
                $(this).removeAttr("disabled");
            }
        });
    },
    /*
     * 图片显示
     */
    imageshow: function () {
        $(".weui_media_hd img").click(function () {
            var that = $(this);
            $.photoBrowser({
                items: [that.attr("src")]
            });
        });
    }
};